
#使用deque对象
from collections import deque
lst=[1,2,3,4,5,6,7]
dq=deque(lst,maxlen=5)
dq.extend([1,2])
print(dq)


#取生成器最近的几个元素
def tail(it,n=5):
    return deque(it,n)

it=iter([1,2,3,4,5,6,7,8,9,0,12,13])
print(tail(it,5))
f=open("test.txt","r")
print(tail(f,5))



